package com.seabook.store.purchase.service;

import java.util.Date;
import java.util.List;

import com.seabook.store.auth.domain.User;
import com.seabook.store.purchase.dao.OrderDao;
import com.seabook.store.purchase.domain.Order;
import com.seabook.store.purchase.domain.OrderUpdate;
import com.seabook.store.purchase.domain.Order.Status;

public class OrderServiceImpl implements OrderService{
    
    private OrderDao orderDao;

    public Order insertOrder(Order order) {
        order = orderDao.insertOrder(order);
        return order;
    }

    public OrderDao getOrderDao() {
        return orderDao;
    }

    public void setOrderDao(OrderDao orderDao) {
        this.orderDao = orderDao;
    }

    public List<Order> getOrderByUserId(int userId) {
        return orderDao.getOrderByUserId(userId);
    }

    public Order getOrderByOrderId(int orderId) {
        return orderDao.getOrder(orderId);
    }

    public void updateOrderStatus(int orderId, Status paid) {
         orderDao.updateOrderStatus(orderId, paid);
    }

    public List<Order> getOrderByStatus(Status paid) {
        // TODO Auto-generated method stub
        return null;
    }

    public void updateOrderStatus(Order order, User user) {
        OrderUpdate update = new OrderUpdate();
        update.setComment("Status Update: " + order.getStatus());
        update.setDate(new Date());
        update.setOrderId(order.getOrderId());
        update.setUserId(user.getUserId());
        update.setUserName(user.getUserName());
        update.setStatus(OrderUpdate.Status.NA);
        update.setType(OrderUpdate.Type.UPDATE);
        this.updateOrder(update);
    }

    public void updateOrder(OrderUpdate orderUpdate) {       
        
    }
  
}
